package ttsolver.constraints;

import ttsolver.input.Node;
import ttsolver.input.Train;

public class ConsArriveTime extends DefaultConstraint {
	
	private Train train;
	private Node node;
	
	public ConsArriveTime() {
		super(ConstraintType.CONS_ARRIVE_TIME);
	}	
	
	public ConsArriveTime(Train train, Node node){
		super(ConstraintType.CONS_ARRIVE_TIME);
		this.train = train;
		this.node = node;
	}
	
	public Train getTrain() {
		return train;
	}

	public void setTrain(Train train) {
		this.train = train;
	}

	public Node getNode() {
		return node;
	}

	public void setNode(Node node) {
		this.node = node;
	}
	
	@Override
	public int hashCode(){
		final int prime = 31;
		int result = 1;
		result = prime * result + ((train == null)? 0 : train.getId().intValue());
		result = prime * result
				+ ((node == null) ? 0 : node.getId().intValue());
		return result;
	}
	
	@Override
	public boolean equals(Object obj){
		if(this == obj)
			return true;
		if(obj == null)
			return false;
		if(getClass() != obj.getClass())
			return false;
		
		ConsArriveTime other = (ConsArriveTime) obj;
		
		if(train == null){
			if(other.train != null)
				return false;
		}else if(!train.equals(other.train)){
			return false;
		}
		
		if (node == null) {
			if (other.node != null)
				return false;
		} else if (!node.equals(other.node)) {
			return false;
		}
		
		return true;
	}
	
	@Override
	public String toString(){
		String s = "";
		s += (train != null)? train.getId() : "N/A";
		s += (node != null) ? "," + String.valueOf(node.getId()) : "";
		return "Hora_Chegada_(" + s + "):\n";
	}

}
